//
//  RechargeListView.m
//  PlayCatchGame
//
//  Created by 流言 on 2018/2/6.
//  Copyright © 2018年 清正. All rights reserved.
//

#import "RechargeListView.h"

#import "RechargeListCell.h"

@interface RechargeListView() <UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (copy, nonatomic) ClickBlock buttonBlock;

@end

@implementation RechargeListView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.dataArray =@[@{@"imageName":@"chongzhi_jingdou_1", @"title":@"200金豆", @"money":@(5.00)},
                      @{@"imageName":@"chongzhi_jingdou_2", @"title":@"500金豆", @"money":@(10.00)},
                      @{@"imageName":@"chongzhi_jingdou_3", @"title":@"800金豆", @"money":@(15.00)},
                      @{@"imageName":@"chongzhi_jingdou_4", @"title":@"1000金豆", @"money":@(18.00)},
                      @{@"imageName":@"chongzhi_jingdou_5", @"title":@"1500金豆", @"money":@(20.00)},
                      @{@"imageName":@"chongzhi_jingdou_6", @"title":@"2000金豆", @"money":@(25.00)}].mutableCopy;
}

- (void)setDataArray:(NSMutableArray *)dataArray {
    if (_dataArray !=dataArray) {
        _dataArray =dataArray;
    }
    [self.tableView reloadData];
}

- (IBAction)colseButtonClick:(UIButton *)sender {
    if (self.buttonBlock) {
        self.buttonBlock(sender, nil);
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    return 55;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    RechargeListCell *cell =[tableView dequeueReusableCellWithIdentifier:@"RechargeListCell"];
    if (!cell) {
        cell =[RechargeListCell findCellWithIdentifier:@"RechargeListCell"];
        cell.selectionStyle =UITableViewCellSelectionStyleNone;
    }
    NSDictionary *dataDict =self.dataArray[indexPath.row];
    cell.dataDict =dataDict;
    [cell didButtonClickBlock:^(UIButton *button) {
        if (self.buttonBlock) {
            self.buttonBlock(button, dataDict);
        }
    }];
    return cell;
}

- (void)buttonClickBlock:(ClickBlock)newBlock {
    self.buttonBlock =newBlock;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
